/******************************************************************************
 * @File name   :      ProxyDatasource.java
 *
 * @Author      :      Brenda Yin
 *
 * @Date        :      2012-6-15
 *
 * @Copyright Notice: 
 * Copyright (c) 2014 DMS, Inc. All  Rights Reserved.
 * This software is published under the terms of the DMS Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * 
 * ----------------------------------------------------------------------------
 * Date                   Who         Version        Comments
 * 2012-6-15 下午09:21:54        Brenda Yin     1.0            Initial Version
 *****************************************************************************/
package com.cap.bts.framework.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.Connection;

import javax.sql.DataSource;

/**
 *
 */
public class ProxyDataSource implements InvocationHandler {

	private DataSource ds;
	
	public ProxyDataSource(DataSource ds){
		this.ds = ds;
	}
	
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		Connection conn = null;
		if (method.getName().equals("getConnection")) {

			conn = (Connection) method.invoke(ds);
			conn = (Connection) Proxy.newProxyInstance(conn.getClass()
					.getClassLoader(), new Class[] { Connection.class },
					new ConnProxy(conn));
			return conn;
		}

		// 姝ｅ父杩斿洖
		return method.invoke(ds, args);
	}

}
